<?php

/**
 * This file is part of the Codizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Codizer Core Team <team@codizer.org>
 * @package     Codizer
 */

function smarty_function_i18n($params, &$smarty)
{
	if(isset($params['base'])) 
	{
		$_SESSION['i18n'] = $params['base'];
		return null;
	}
	
	if(isset($_SESSION['i18n']) && !strstr($params['key'], "locale."))
	{
		$localeParam = $_SESSION['i18n'].".".$params['key'];
	}
	else
	{
		$localeParam = $params['key'];
	}
	
	$values = array();
	
	foreach($params as $key => $param)
	{
		if($key != "base" && $key != "key")
		{
			$values[$key] = $param;			
		}
	}
	
	$lang = f_core_Context::getInstance()->getDisplayLang();
   	
  	$locale = f_locale_Manager::getLocale($localeParam, $lang, $values);

  	return nl2br($locale);
}